<template>
  <div class="app-container">
    <div class="top">

      <!-- <div class="asin_box">
        <span style="margin-right: 15px;font-size: 14px;color: #606266;font-weight: 700;">单位</span>
        <div >
          <el-cascader size="small" style="width:200px" v-model="deepId" placeholder="请选择" class="row_a" :options="deptList"
            ref='ownArea' @change="selectArea" :props="{ checkStrictly: true, label: 'deptName', value: 'deptId' }" :show-all-levels="false"
            clearable>
          </el-cascader>
        </div>
      </div>

      <div style="margin-right: 15px;">
        <span style="margin-right: 10px;font-size: 14px;color: #606266;font-weight: 700;">舆情分类</span>
        <el-select size="small" style="width:200px" v-model="pscategory" placeholder="请选择">
          <el-option v-for="item in dict.type.ps_category" :key="item.value" :label="item.label" :value="parseInt(item.value)">
          </el-option>
        </el-select>
      </div> -->

      <el-form style="margin-top: 17px;"   size="small" :inline="true"
        v-show="showSearch" label-width="68px">
        <el-form-item label="时间范围">
          <el-date-picker v-model="daterangeReleaseTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
            range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

    </div>

    <el-table max-height="600" v-loading="loading" :data="StatisticsList" @selection-change="handleSelectionChange">

      <el-table-column type="selection" width="55" align="center" />
      <el-table-column  type="index" label="序号" width="55" align="center" :index="indexMethod" />
      <el-table-column label="单位" min-width="200" align="center" prop="departName" />
      <el-table-column label="待处理" min-width="200" align="center" prop="needDeal" />
      <el-table-column label="待签收" min-width="200" align="center" prop="needSign" />
      <el-table-column label="已处理" min-width="200" align="center" prop="dealEd" />
      <el-table-column label="已分派" min-width="200" align="center" prop="sended" />
      <el-table-column label="总数" min-width="200" align="center" prop="total" />

    </el-table>

  </div>
</template>

<script>
import { listReport, getReport, delReport, addReport, updateReport, dispose, appear, withdraw } from "@/api/report/report";
import { getStatistics } from "@/api/home/home";
import { addPublicsentiment } from "@/api/publicsentiment/publicsentiment";
import { listDept } from "@/api/system/dept";
import { apportionPublicsentiment } from "@/api/publicsentiment/publicsentiment";

export default {
  name: "Report",
  dicts: ['ps_category'],
  data() {
    return {
      // 舆情分类的值
      pscategory: '',
      deepId:'',
      //单位列表
      deptList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 舆情t统计表格数据
      StatisticsList: [],

      // 上报内容时间范围
      daterangeReleaseTime: [],
      // 上报内容时间范围
      daterangeReportTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        releaseTime: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
    this.getUnitList()
  },
  methods: {
    selectArea (e) {
        this.$nextTick(() => {
            this.$refs.ownArea.dropDownVisible = false;
        })
    },
     indexMethod(index) {
        index = (index + 1) + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
        return index
      },
    //获取单位列表
    getUnitList() {
      listDept().then(response => {
        let data = this.handleTree(response.data, "deptId")[0].children;
        data.map(item => {
          item.disabled = true
        })
        this.deptList = data
      });
    },
    /** 查询舆情统计列表 */
    getList() {
      this.loading = true;
      // this.queryParams.params = {};
      if(this.deepId.length){
        this.deepId = this.deepId[this.deepId.length-1]
      }
      let queryParams = {
        category:this.pscategory,
        departId:this.deepId,
        startDate:'',
        endDate:'',
      }
      if (null != this.daterangeReleaseTime && '' != this.daterangeReleaseTime) {
        queryParams["startDate"] = this.daterangeReleaseTime[0];
        queryParams["endDate"] = this.daterangeReleaseTime[1];
      }else{
        queryParams["startDate"] = '';
        queryParams["endDate"] = '';
      }
      getStatistics(queryParams).then(res=>{
        this.loading = false;
        this.StatisticsList = res.data
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.pscategory = ''
      this.deepId = ''
      this.daterangeReleaseTime = []
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
  }
};
</script>
<style scoped lang="scss">
.top {
  display: flex;
  align-items: center;
}

.asin_box {
  // width: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;

  .r_select {
    width: 75%;
  }
}
</style>
